package com.huo15.myapplication;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.util.LruCacheKt;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.huo15.myapplication.util.PermissionUtil;

import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends AppCompatActivity {

    private Button btn1;
    private int mRequestCode=1111;
    private String[] mPermissions={Manifest.permission.WRITE_EXTERNAL_STORAGE};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn1=(Button) findViewById(R.id.btn1);
        MainActivity activity = this;
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                boolean res = PermissionUtil.checkMultiPermission(activity, mPermissions, mRequestCode);
                if (res){
                    Toast.makeText(getApplicationContext(),"你点击了按钮"+res,Toast.LENGTH_SHORT).show();

                }else {
                    Toast.makeText(getApplicationContext(),"你点击了按钮"+res,Toast.LENGTH_SHORT).show();
                }
            }
        });

    }


    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == mRequestCode) {
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                Toast.makeText(this,"权限成功："+permissions.toString(),Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(this,"权限失败："+permissions.toString(),Toast.LENGTH_SHORT).show();
            }
        }
    }
}